package com.hk.yajin.function.members.activity;

import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hk.yajin.R;
import com.hk.yajin.base.BaseActivity;
import com.hk.yajin.manager.UserInfoManager;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMWeb;

import org.xutils.common.util.LogUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class InviteFriendActivity extends BaseActivity {

    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.tv_invite)
    TextView tvInvite;
    @BindView(R.id.tv_code)
    TextView tvCode;

    @BindView(R.id.activity_invite_friend)
    LinearLayout activityInviteFriend;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_invite_friend);
        ButterKnife.bind(this);
        intiView();
    }

    private void intiView() {
        initToolBar(R.string.invite_friend);
        String code = UserInfoManager.getInstance().getUserInfo().getInvite_code();
        if (!TextUtils.isEmpty(code)) {
            tvCode.setText("邀请码:" + code);
            tvCode.setVisibility(View.VISIBLE);
        }else{
            tvCode.setVisibility(View.INVISIBLE);
        }
    }


    @OnClick(R.id.tv_invite)
    public void onViewClicked() {
        share();
    }

    private void share() {
        UMWeb shareUMVideo = new UMWeb("https://www.baidu.com");
        shareUMVideo.setTitle(getString(R.string.app_name));
        shareUMVideo.setThumb(new UMImage(this, R.mipmap.applogo));
        shareUMVideo.setDescription("发现一个提供外汇内部消息的app~赶紧来看看");
        new ShareAction(this).withMedia(shareUMVideo)
                .setDisplayList(SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE, SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE)
                .setCallback(new UMShareListener() {
                    @Override
                    public void onStart(SHARE_MEDIA share_media) {

                    }

                    @Override
                    public void onResult(SHARE_MEDIA share_media) {

                    }

                    @Override
                    public void onError(SHARE_MEDIA share_media, Throwable throwable) {

                        if (throwable != null) {
                            // showShortToast(throwable.getMessage());
                            LogUtil.d("错误：" + throwable.getMessage());
                        }
                    }

                    @Override
                    public void onCancel(SHARE_MEDIA share_media) {
                        showShortToast("onCancel");
                    }
                }).open();
    }
}
